import { BASE_URL } from "./url";

export const request = (params) => {
    // 增加遮罩层
    wx.showLoading({
        title:'正在加载中....'
    })
    //获取请求头
  let header = { ...params.header };
    // 判断地址是否包含我的请求地址
  if (params.url.includes("/my/")) {
    header["Authorization"] = wx.getStorageSync("token");
  }

  return new Promise(function (resolve, reject) {
     wx.request({
        ...params,
        hader:header,
        url:BASE_URL+params.url,
        success:(res)=>{
            resolve(res.data.message)
        },
        fails:(err)=>{
            reject(err)
        },
        complete:()=>{
            // 取消加载
            wx.hideLoading()
        }
     })
  });
};
